package com.tduck.cloud.report.data.business.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tduck.cloud.common.util.QueryWrapperUtils;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.report.data.business.entity.ReportDataSetEntity;
import com.tduck.cloud.report.data.business.service.ReportDataSetService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tduck.cloud.common.validator.group.AddGroup;


/**
 * 数据集管理
 *
 * @author tduck
 * @since 2023-06-23 16:09:05
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/data/dataSet")
public class ReportDataSetController {

    private final ReportDataSetService reportDataSetService;

    /**
     * 查询数据集管理列表
     */
    @GetMapping("/page")
    public Result queryPage(Page page, ReportDataSetEntity dataSet) {
        return Result.success(reportDataSetService.page(page, QueryWrapperUtils.toSimpleQuery(dataSet)));
    }


    /**
     * 获取数据集管理详细信息
     *
     * @param id 主键
     */
    @GetMapping(value = "/{id}")
    public Result<ReportDataSetEntity> getInfo(@PathVariable("id") Long id) {
        return Result.success(reportDataSetService.getById(id));
    }

    /**
     * 新增数据集管理
     */
    @PostMapping("/add")
    public Result<Boolean> add(@Validated(AddGroup.class) @RequestBody ReportDataSetEntity dataSet) {
        return Result.success(reportDataSetService.save(dataSet));
    }

    /**
     * 修改数据集管理
     */
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody ReportDataSetEntity dataSet) {
        return Result.success(reportDataSetService.updateById(dataSet));
    }

    /**
     * 删除数据集管理
     *
     * @param ids 主键串
     */
    @PostMapping("/delete/{ids}")
    public Result<Boolean> delete(@PathVariable List<Long> ids) {
        return Result.success(reportDataSetService.removeByIds(ids));
    }
}
